//
//  HNSH_BusinessCircleRecordViewController.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/9/26.
//

#import "HNSH_BusinessCircleRecordViewController.h"

#import "HNSH_BusinessCircleRecordCell.h"

@interface HNSH_BusinessCircleRecordViewController ()

/* listAry */
@property (nonatomic, strong) NSMutableArray *listAry;

@end

static NSString *HNSH_BusinessCircleRecordCellID = @"HNSH_BusinessCircleRecordCellID";

@implementation HNSH_BusinessCircleRecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self configTableView];
}

- (void)configTableView {
    [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    [self.tableView registerClass:[HNSH_BusinessCircleRecordCell class] forCellReuseIdentifier:HNSH_BusinessCircleRecordCellID];
    
    [self setupEmpty:self.tableView image:[UIImage imageNamed:@"empty_list_data"] title:@""];
    [self setupRefresh:self.tableView option:ST_RefreshDefault];
}

- (void)refreshData:(NSInteger)page {
    [HNSH_ShopNetServer requestBusinessCircleVoucherListWithPageNum:page type:self.parameter success:^(ST_BaseNetModel * _Nullable responseObject) {
        [self endRefresh:YES];
        if (responseObject.code == 0) {
            if (page == 1) {
                [self.listAry removeAllObjects];
            }
            NSArray *ary = [NSArray yy_modelArrayWithClass:[HNSH_BusinessCircleRecordModel class] json:responseObject.resultset[@"list"]];
            [self.listAry addObjectsFromArray:ary];
            [self.tableView reloadData];
            [self endRefresh:ary.count >= 10];
        }
    } Failure:^(NSError * _Nullable error) {
        
    }];
}

#pragma mark lazy
- (NSMutableArray *)listAry {
    if (!_listAry) {
        _listAry = [NSMutableArray arrayWithCapacity:0];
    }
    return _listAry;
}

#pragma mark - delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.listAry.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 12.01f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [UIView new];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [UIView new];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HNSH_BusinessCircleRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:HNSH_BusinessCircleRecordCellID];
    cell.model = self.listAry[indexPath.section];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//    HNSH_BusinessCircleDetailViewController *vc = [[HNSH_BusinessCircleDetailViewController alloc]init];
//    vc.model = self.listAry[indexPath.section];
//    [[UIViewControllerHelper findCurrentShowingViewController].navigationController pushViewController:vc animated:YES];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
